
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/11/2013 23:57:32
-- Generated from EDMX file: E:\Study Data\MVCbulletinmanagement\Bulletin\BulletinModel\BulletinModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [BulletinDB];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BulletinItem_Bulletin]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BulletinItems] DROP CONSTRAINT [FK_BulletinItem_Bulletin];
GO
IF OBJECT_ID(N'[dbo].[FK_Feedback_Feedback]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Feedbacks] DROP CONSTRAINT [FK_Feedback_Feedback];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Bulletins]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Bulletins];
GO
IF OBJECT_ID(N'[dbo].[BulletinItems]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BulletinItems];
GO
IF OBJECT_ID(N'[dbo].[Feedbacks]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Feedbacks];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Bulletins'
CREATE TABLE [dbo].[Bulletins] (
    [Name] nvarchar(550)  NOT NULL,
    [ID] int IDENTITY(1,1) NOT NULL,
    [StartDate] datetime  NOT NULL,
    [DueDate] datetime  NOT NULL,
    [Visible] bit  NOT NULL,
    [TextFeedbackEnabled] bit  NOT NULL,
    [StarFeedbackEnabled] bit  NOT NULL,
    [Description] nvarchar(max)  NULL
);
GO

-- Creating table 'BulletinItems'
CREATE TABLE [dbo].[BulletinItems] (
    [ProjectSN] nvarchar(350)  NOT NULL,
    [ProjectTitle] nvarchar(550)  NOT NULL,
    [County] nvarchar(50)  NOT NULL,
    [School] nvarchar(350)  NOT NULL,
    [TeacherName] nvarchar(50)  NOT NULL,
    [Comment] nvarchar(max)  NULL,
    [Conclusion] nvarchar(max)  NULL,
    [BulletinID] int  NOT NULL
);
GO

-- Creating table 'Feedbacks'
CREATE TABLE [dbo].[Feedbacks] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [TextValue] nvarchar(300)  NULL,
    [StarValue] int  NULL,
    [ProjectSN] nvarchar(350)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Bulletins'
ALTER TABLE [dbo].[Bulletins]
ADD CONSTRAINT [PK_Bulletins]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ProjectSN] in table 'BulletinItems'
ALTER TABLE [dbo].[BulletinItems]
ADD CONSTRAINT [PK_BulletinItems]
    PRIMARY KEY CLUSTERED ([ProjectSN] ASC);
GO

-- Creating primary key on [ID] in table 'Feedbacks'
ALTER TABLE [dbo].[Feedbacks]
ADD CONSTRAINT [PK_Feedbacks]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [BulletinID] in table 'BulletinItems'
ALTER TABLE [dbo].[BulletinItems]
ADD CONSTRAINT [FK_BulletinItem_Bulletin]
    FOREIGN KEY ([BulletinID])
    REFERENCES [dbo].[Bulletins]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BulletinItem_Bulletin'
CREATE INDEX [IX_FK_BulletinItem_Bulletin]
ON [dbo].[BulletinItems]
    ([BulletinID]);
GO

-- Creating foreign key on [ProjectSN] in table 'Feedbacks'
ALTER TABLE [dbo].[Feedbacks]
ADD CONSTRAINT [FK_Feedback_Feedback]
    FOREIGN KEY ([ProjectSN])
    REFERENCES [dbo].[BulletinItems]
        ([ProjectSN])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Feedback_Feedback'
CREATE INDEX [IX_FK_Feedback_Feedback]
ON [dbo].[Feedbacks]
    ([ProjectSN]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------